<?php
    require_once("condb.php");
    require_once("functions.php");
    
    $output = array();
    $info = isset($_GET["info"]) ? $_GET["info"] : "";
    if(!empty($info)){
        $info = urldecode(base64_decode($info));
        parse_str($info, $request);    
        
        $token = isset($request["token"]) ? cleanQuery($request["token"]) : "";
        if($token=="TAoViEC@)!#2012"){
            
            /*
            * Lấy cú pháp sms
            */
            
            $syntax = getSmsSyntax();            
            
            $data = array();
            $data["type"] = isset($request["type"]) ? intval($request["type"]) : 0;            
            $data["refCode"] = isset($request["refCode"]) ? cleanQuery($request["refCode"]) : 0;            
            $data["appId"] = isset($request["appId"]) ? intval($request["appId"]) : 0;            
            
            if(!empty($data["type"]) && !empty($data["refCode"]) && !empty($data["appId"])){
                
                if($data["type"]==1){
                    
                    $serviceCode = $syntax[1]["serviceCode"];
                    $syntax_text = $syntax[1]["syntax"];
                     
                } else if($data["type"]==2){
                    
                    $serviceCode = $syntax[2]["serviceCode"];
                    $syntax_text = $syntax[2]["syntax"];
                    
                } else if($data["type"]==3){
                    
                    $serviceCode = $syntax[3]["serviceCode"];
                    $syntax_text = $syntax[3]["syntax"];
                    
                }
                
                if(in_array($data["type"], array(1, 2, 3))){
                    $sms["message"] = "Nhắn tin kích hoạt";
                    $sms["mo"] = $syntax_text . " " . $data["type"] . " " . $data["appId"] . " " . $data["refCode"];
                    $sms["serviceCode"] = $serviceCode;
                }
                                    
                $output["status"] = 1;
                $output["msg"] = "Success Request";
                    
            } else {
                $output["status"] = 4;
                $output["msg"] = "Invalid Request";                        
            }
                
        } else {
            $output["status"] = 3;
            $output["msg"] = "Invalid Request";    
        }
    } else {
        $output["status"] = 2;
        $output["msg"] = "Invalid Request";
    }
            
    $output["sms"] = isset($sms) ? $sms : array();    
    echo json_encode($output);
    
    
?>
